﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var name = textBox1.Text;
            var pwd = textBox2.Text;
            var newPwd = textBox3.Text;

            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "")
            {
                if (pwd == newPwd)
                {
                    string sql = string.Format("insert into Users values('{0}','{1}')", name, pwd);

                    DataTable dat = DbHelper.GetDataTable(sql);


                    var dell = dat.Rows.Count;

                    if (dell == 1)
                    {
                        MessageBox.Show("已存在用户名!");
                    }
                    else
                    {
                        string str = string.Format("insert into Users values ('{0}','{1}')",name,pwd);
                        var ary = DbHelper.AddOrEditSave(sql);
                        if (ary >= 1)
                        {
                            MessageBox.Show("恭喜你，注册成功！");
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("很抱歉，注册失败。");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("两次输入的密码不相等，请重新输入！");
                }
            }
            else
            {
                MessageBox.Show("请注意查看，注册信息不能为空!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
